package com.gxa.zhonglong.controller;

import com.gxa.zhonglong.common.JsonResult;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.pojo.GoodsPrice;
import com.gxa.zhonglong.pojo.GoodsWeight;
import com.gxa.zhonglong.service.GoodsPriceService;
import com.gxa.zhonglong.service.GoodsWeightService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author NITRO
 */

@Api
@CrossOrigin
@RestController
@RequestMapping("/goodsWeight")
public class GoodsWeightController {

    @Autowired
    private GoodsWeightService goodsWeightService;

    @ApiOperation(value = "添加商品重量")
    @PostMapping("/addGoodsWeight")
    public Map addGoodsWeight( GoodsWeight goodsWeight) throws BusinessException {
        JsonResult jsonResult=new JsonResult();
        goodsWeightService.addGoodsWeight(goodsWeight);
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }


    @PostMapping("/deleteGoodsWeight")
    @ApiOperation("删除商品重量")
    public Map<String,Object> deleteGoodsWeight(@RequestBody Map<String,List<Long>> ids) throws BusinessException {
        goodsWeightService.deleteGoodsWeight(ids.get("ids"));
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }

    @ApiOperation(value = "修改商品重量")
    @PostMapping("/updateGoodsWeight")
    public Map updateWeight( GoodsWeight goodsWeight) throws BusinessException {
        JsonResult jsonResult = new JsonResult();
        goodsWeightService.updateGoodsWeight(goodsWeight);
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }

    @ApiOperation(value = "查询商品重量")
    @PostMapping("/getGoodsWeightList")
    public Map getGoodsWeightList(){


        List<GoodsWeight> goodsWeightList = goodsWeightService.getGoodsWeightList();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(goodsWeightList);
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }
}
